package com.itheima.controller;

import com.itheima.dto.QuestionsAddDto;
import com.itheima.dto.QuestionsListDto;
import com.itheima.pojo.Questions;
import com.itheima.service.QuestionsAuditsService;
import com.itheima.service.QuestionsRecordsService;
import com.itheima.service.QuestionsService;
import com.itheima.vo.PageResultVO;
import com.itheima.vo.audits.QuestionsAuditsVO;
import com.itheima.vo.questions.QuestionsVO;
import com.itheima.vo.records.QuestionsRecordsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/questions")
public class QuestionsController {
    @Autowired
    private QuestionsAuditsService questionsAuditsService;
    @Autowired
    private QuestionsRecordsService questionsRecordsService;
    @Autowired
    private QuestionsService questionsService;

    /**
     * 审核意见
     * @param id
     * @return
     */
    @GetMapping("/{id}/auditOpinions")
    public List<QuestionsAuditsVO> getOpinions(@PathVariable Integer id){
        return questionsAuditsService.findById(id);
    }

    /**
     * 出题记录
     * @param id
     * @return
     */
    @GetMapping("/{id}/setRecords")
    public List<QuestionsRecordsVO> getRecords(@PathVariable Integer id){
        return questionsRecordsService.findById(id);
    }

    /**
     * 基础题库列表
     * @param questionsListDto
     * @return
     */
    @GetMapping
    public PageResultVO<QuestionsVO> queryPageList(QuestionsListDto questionsListDto){
        return questionsService.findPage(questionsListDto);
    }

    @DeleteMapping("/{id}")
    public String delete(@PathVariable Integer id){
        return questionsService.delete(id);
    }

    @PostMapping
    public Integer add(@RequestBody QuestionsAddDto questionsAddDto){
        return questionsService.add(questionsAddDto);
    }

    @GetMapping("/{id}")
    public QuestionsVO getDetails(@PathVariable Integer id){
        return questionsService.findById(id);
    }

    @PutMapping("/{id}")
    public String edit(@PathVariable Integer id, @RequestBody QuestionsAddDto questionsAddDto){
        questionsAddDto.setId(id);
        return questionsService.edit(questionsAddDto);
    }

    @PostMapping("/batch")//未完成
    public String batch(){
        return null;
    }

    @PostMapping("/choice/{id}/{publishState}")
    public String choice(@PathVariable Integer id, @PathVariable Integer publishState){
        return questionsService.setChoice(id,publishState);
    }

    @GetMapping("/choice")
    public PageResultVO getChoice(QuestionsListDto questionsListDto){
        return questionsService.findChoicePage(questionsListDto);
    }

    @GetMapping("/randoms")
    public PageResultVO getTopicGroup(Integer page, Integer pagesize, String keyword){
        return questionsService.findRandomsByKeyword(page,pagesize,keyword);
    }

    @DeleteMapping("/randoms/{id}")//未完成
    public String deleteGroup(@PathVariable Integer id){
        return null;
    }

    @PatchMapping("/choice/{id}/{choiceState}")
    public String setChoice(@PathVariable Integer id, @PathVariable Integer choiceState){
        return questionsService.setChoice1(id,choiceState);
    }

    @PostMapping("/check/{id}")
    public String check(@PathVariable Integer id, @RequestBody Questions questions){return questionsService.setCheck(id,questions);}
}
